package com.sudo.common.utils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

@ApiModel(value = "分页对象模型")
public class PageBO {
    @ApiModelProperty(value = "当前页", required = true, example = "1")
    @Min(value = 1, message = "当前页必须大于等于1")
    private Integer page = 1;

    @ApiModelProperty(value = "页面大小", required = true, example = "10")
    @Min(value = 1, message = "页面大小必须大于等于1")
    @Max(value = 100,message = "页面大小必须小于等于100")
    private Integer pageSize = 10;

    @ApiModelProperty(value = "排序")
    private Sort sort;

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Sort getSort() {
        return sort;
    }

    public void setSort(Sort sort) {
        this.sort = sort;
    }

    public PageBO() {
    }

    public PageBO(@Min(value = 1, message = "当前页必须大于等于1") Integer page, @Min(value = 1, message = "页面大小必须大于等于1") Integer pageSize, Sort sort) {
        this.page = page;
        this.pageSize = pageSize;
        this.sort = sort;
    }

    @ApiModel(value = "排序对象模型")
    public static class Sort {
        @ApiModelProperty(value = "排序参数")
        private String prop;
        @ApiModelProperty(value = "排序方式('desc' or 'asc')")
        private String order;

        public String getProp() {
            return prop;
        }

        public void setProp(String prop) {
            this.prop = prop;
        }

        public String getOrder() {
            return order;
        }

        public void setOrder(String order) {
            this.order = order;
        }

        public Sort() {
        }

        public Sort(String prop, String order) {
            this.prop = prop;
            this.order = order;
        }
    }
}
